package org.logsin37.tool.eurekamanager.config;

import org.logsin37.tool.eurekamanager.EurekaManagerApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Eureka Manager Auto Configuration
 *
 * @author logsin37 2020/01/19 15:34
 */
@Configuration
@Import(RouteFilterConfiguration.class)
@ComponentScan(basePackageClasses = EurekaManagerApplication.class)
public class EurekaManagerAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(ObjectMapper.class)
    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        // 返回值过滤null或""值
        objectMapper
                .setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
                .setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return objectMapper;
    }

}
